package com.moyingren.springcloud.service;

import com.moyingren.springcloud.pojo.Department;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;


@Service
public class RestTemplateImpl {

    @Resource(name = "header1")
    private HttpHeaders httpHeaders;

    private RestTemplate restTemplate;

    public RestTemplate getRestTemplate() {
        return restTemplate;
    }

    @Autowired
    public void setRestTemplate(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }

    public Object exchange(String url, HttpMethod method, Object type) {
        return restTemplate.exchange(url, method, new HttpEntity<Object>(httpHeaders), Department.class).getBody();
//        return restTemplate.exchange(url, method, new HttpEntity<Object>(httpHeaders), type.getClass()).getBody();
    }
}
